package com.lei.zjs.web.action;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.itcast.crm.domain.Customer;
import cn.itcast.crm.service.CustomerService;

import com.lei.zjs.service.ebi.NoticebillService;
import com.lei.zjs.service.ebi.StaffService;
import com.lei.zjs.utils.BOSContext;
import com.lei.zjs.vo.Noticebill;
import com.lei.zjs.vo.Staff;
import com.lei.zjs.vo.User;
import com.lei.zjs.web.action.base.BaseAction;

/**
 * 业务受理Action
 * @author Spinacia
 *
 */
@Controller
@Scope("prototype")
public class NoticebillAction extends BaseAction<Noticebill>{

	private String phone;

	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	//注入远程调用服务接口
	@Resource
	private CustomerService customerService;
	
	@Resource
	private NoticebillService noticebillService;
	
	//通过手机号查询用户信息
	public String findCustomerByphone() throws IOException{
		Customer customer = customerService.findCustomerByphone(phone);
		
		String[] excludes = new String[]{"decidedzone_id"};
		this.writeObject2String(customer, excludes );
		return NONE;
	}
	
	//保存业务受理信息
	public String save(){
		//封装当前操作人员
		User user = BOSContext.getLoginUser();
		model.setUser(user);
		
		noticebillService.save(model);
		return "list";
	}
	
	//查找没有关联取派员的通知单
	public String findnoassociations() throws IOException{
		DetachedCriteria dc = DetachedCriteria.forClass(Noticebill.class);
		dc.add(Restrictions.isNull("staff"));
		List<Noticebill> list = noticebillService.findnoassociations(dc);
		
		String[] excludes = new String[]{"user","staff","workbills"};
		this.writeJsonArray2String(list, excludes);
		return NONE;
	}
	
	//人工调度通知单
	public String manualDispatch(){
		noticebillService.manualDispatch(model);
		return "list";
	}
	
}
